$(function () {
    videoInit(videoData)
});

// 视频数据
let videoData = [
    // 入门
    {
        id: "hceap-threshold",
        name: "快速了解EAP",
        title: "入门介绍",
        desc: "",
        url: "/page/eapschool/videoPlay.html",
        imgUrl: "/images/eapschool/videoTutorial/block1-1.png",
        duration: "00:02:00",
        watch: "10125",
        children: [
            {
                id: "",
                name: "EAP平台介绍",
                desc: "EAP工具功能，场景应用",
                url: ""
            },
            {
                id: "",
                name: "创建项目",
                desc: "丰富的模板，平台版本含义，多数据库，多端应用",
                url: ""
            },
            {
                id: "",
                name: "建模端介绍",
                desc: "工程树(节点，复制/粘贴，右击功能点)，工具条，属性面板",
                url: ""
            },
            {
                id: "",
                name: "HelloWord",
                desc: "数据增，删，改，查",
                url: ""
            }
        ]

    },
    // 数据库
    {
        id: "hceap-database",
        name: "数据库",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-2.png",
        duration: "",
        watch: "8567",
        children: [
            {
                id: "",
                name: "数据源",
                desc: "多数据源，多类型数据库，执行SQL",
                url: ""
            },
            {
                id: "",
                name: "数据表",
                desc: "系统字段，导入字段，同步结构",
                url: ""
            },
            {
                id: "",
                name: "数据库编程",
                desc: "存储过程，视图，调度",
                url: ""
            },
        ]
    },
    // 数据集
    {
        id: "hceap-dataset",
        name: "数据集",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-1.png",
        duration: "",
        watch: "6378",
        children: [
            {
                id: "",
                name: "实体介绍",
                desc: "实体概念，不同实体类型，主从，冗余主从，关联，合并，复制",
                url: ""
            },
            {
                id: "",
                name: "实体字段介绍",
                desc: "不同字段类型，同步字段，冗余，显示格式，查询操作符，更新汇总",
                url: ""
            },
            {
                id: "",
                name: "逻辑字段",
                desc: "SQL字段，JAVA字段",
                url: ""
            },
            {
                id: "",
                name: "条件字段",
                desc: "用户参数，系统参数，条件参数",
                url: ""
            },
            {
                id: "",
                name: "SQL实体，Mongo实体",
                desc: "SQL实体字段导入，SQL实体更新，Mongo对象字段",
                url: ""
            },
            {
                id: "",
                name: "实体入门",
                desc: "元素，查询方案，更新规则，更新删除检测",
                url: ""
            },
            {
                id: "",
                name: "数据填充",
                desc: "自动填充，更新汇总",
                url: ""
            },
            {
                id: "",
                name: "数据实体策略，触发器",
                desc: "策略，触发器",
                url: ""
            },
            {
                id: "",
                name: "数据约束",
                desc: "字段约束，实体约束",
                url: ""
            },
            {
                id: "",
                name: "数据导入，导出",
                desc: "Excel导入，Excel导出，主从导出",
                url: ""
            },
            {
                id: "",
                name: "触发器",
                desc: "增，删，改触发器",
                url: ""
            },
            {
                id: "",
                name: "实体事件",
                desc: "查询前后事件，更新前后事件，常用函数与数据类",
                url: ""
            },
        ]
    },
    // 模型
    {
        id: "hceap-mx",
        name: "模型",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-2.png",
        duration: "",
        watch: "6032",
        children: [
            {
                id: "",
                name: "枚举数据选择",
                desc: "枚举模型，枚举查找定义，多字段返回，表单表现形式",
                url: ""
            },
            {
                id: "",
                name: "数据集数据选择",
                desc: "数据模型，数据查找定义，多数据多字段返回，主从返回，表单表现形式",
                url: ""
            },
            {
                id: "",
                name: "数据集树型数据选择",
                desc: "树模型，数据查找定义，级联返回，表单表现形式",
                url: ""
            },
        ]
    },
    // Web端视图设计
    {
        id: "hceap-webview",
        name: "Web端视图设计",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-1.png",
        duration: "",
        watch: "5892",
        children: [
            {
                id: "",
                name: "制单",
                desc: "数据工具条，表单行列设置，表单默认表现形式与数据集字段的关系",
                url: ""
            },
            {
                id: "",
                name: "查询-1",
                desc: "查询面板行列设置，查询面板默认表现形式与数据集字段的关系，查询方案",
                url: ""
            },
            {
                id: "",
                name: "查询-2",
                desc: "条件面板，排序条，分页",
                url: ""
            },
            {
                id: "",
                name: "数据集",
                desc: "数据追加，加载从表，暂存，自动刷新，激活，默认条件",
                url: ""
            },
            {
                id: "",
                name: "数据集事件",
                desc: "保存前后事件，查询前后事件，修改前后事件",
                url: ""
            },
            {
                id: "",
                name: "表单-字段表现形式-1",
                desc: "评分，附件，开关(switch)，图片，HTML编辑器",
                url: ""
            },
            {
                id: "",
                name: "表单-字段表现形式-2",
                desc: "进度条，滑块，颜色，地图座标",
                url: ""
            },
            {
                id: "",
                name: "表单-动态表单",
                desc: "数据集动态表单",
                url: ""
            },
            {
                id: "",
                name: "表格入门",
                desc: "默认表现形式与数据集字段的关系，列宽，排序，汇总，多选，填满容器，编辑配置，菜单配置",
                url: ""
            },
            {
                id: "",
                name: "表格-外观设置",
                desc: "个性行，个性列，个性表头",
                url: ""
            },
            {
                id: "",
                name: "表格-多表头与数跨行列",
                desc: "列配置，跨行跨列",
                url: ""
            },
            {
                id: "",
                name: "表格-动态表头",
                desc: "数据集动态表头",
                url: ""
            },
            {
                id: "",
                name: "表格-树展示",
                desc: "表格树",
                url: ""
            },
            {
                id: "",
                name: "功能跳转",
                desc: "下推，下推按钮，下推链接，网格操作列",
                url: ""
            },
            {
                id: "",
                name: "树型数据维护",
                desc: "树控件，树查询面板",
                url: ""
            },
            {
                id: "",
                name: "数据列表",
                desc: "列表项，列表嵌套，空模板",
                url: ""
            },
            {
                id: "",
                name: "布局-Flex布局",
                desc: "根页面Flex布局，Flex布局，栅格行，栅格列",
                url: ""
            },
            {
                id: "",
                name: "布局-综合布局，浮动布局",
                desc: "综合布局，上下左右区，浮动布局，左中右浮动",
                url: ""
            },
            {
                id: "",
                name: "容器组件",
                desc: "选项卡，卡片，弹出框",
                url: ""
            },
            {
                id: "",
                name: "子页应用",
                desc: "Vue组件，表格-子页",
                url: ""
            },
            {
                id: "",
                name: "自定义代码",
                desc: "代码块",
                url: ""
            },
            {
                id: "",
                name: "实战案例-工作台",
                desc: "布局，数据读取，自定义代码",
                url: ""
            },
            {
                id: "",
                name: "实战案例-销售管理",
                desc: "表单，表格，主从，数据查找，数据下推",
                url: ""
            },
        ]
    },
    // 移动端视图设计
    {
        id: "hceap-mbview",
        name: "移动端视图设计",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-2.png",
        duration: "",
        watch: "5028",
        children: [
            {
                id: "",
                name: "组件初识",
                desc: "常规组件，导航组件，数据组件，表单组件，布局组件，图表组件概要介绍和案例展示",
                url: ""
            },
            {
                id: "",
                name: "常规组件和导航",
                desc: "通过组件的介绍，配置出一个常规APP首页",
                url: ""
            },
            {
                id: "",
                name: "布局讲解和样式的使用",
                desc: "Flex布局的介绍，行、列、折叠面板、滑动和浮动弹层的使用，使配置的APP首页变的功能丰富且美观",
                url: ""
            },
            {
                id: "",
                name: "数据集引入",
                desc: "讲解数据集的引入和组件绑定数据集的方式及数据集的属性设置",
                url: ""
            },
            {
                id: "",
                name: "表单",
                desc: "配置表单，配置一个通用的表单制单界面及表单详情界面",
                url: ""
            },
            {
                id: "",
                name: "表单-表现形式",
                desc: "使用表现形式，自定义查找，枚举等",
                url: ""
            },
            {
                id: "",
                name: "数据组件介绍",
                desc: "通过案例，讲解数据组件的效果",
                url: ""
            },
            {
                id: "",
                name: "数据组件-列表",
                desc: "讲解列表的多种使用方式",
                url: ""
            },
            {
                id: "",
                name: "数据组件-九宫格",
                desc: "讲解九宫格的多种使用方式",
                url: ""
            },
            {
                id: "",
                name: "数据组件-组合使用",
                desc: "使用数据组件配置出一个相对复杂的功能页面",
                url: ""
            },
            {
                id: "",
                name: "图表组件",
                desc: "图表的介绍：折线图、饼图、柱状图",
                url: ""
            },
            {
                id: "",
                name: "下推",
                desc: "下推配置与介绍：下推查看，下推新增",
                url: ""
            },
            {
                id: "",
                name: "功能与流程",
                desc: "应用中心和任务中心介绍和使用",
                url: ""
            },
            {
                id: "",
                name: "事件讲解和使用",
                desc: "页面事件，组件事件，数据集事件",
                url: ""
            },
            {
                id: "",
                name: "代码块",
                desc: "自定义组件",
                url: ""
            },
            {
                id: "",
                name: "移动端系统设置",
                desc: "app.config，图标库，资源图片，主题设置，小程序设置",
                url: ""
            },
            {
                id: "",
                name: "案例：简易OA",
                desc: "首页，应用中心，任务中心，我的，请假申请单",
                url: ""
            },
            {
                id: "",
                name: "移动端开发工具介绍",
                desc: "开发者APP使用，reload，重启服务器",
                url: ""
            },
            {
                id: "",
                name: "部署",
                desc: "创建部署，配置部署，开发者中心编译",
                url: ""
            },

        ]
    },
    // 定制开发
    {
        id: "hceap-dzkf",
        name: "定制开发",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-1.png",
        duration: "",
        watch: "5012",
        children: [
            {
                id: "",
                name: "vue开发",
                desc: "vue开发，资源文件引用，elementui，hiui",
                url: ""
            },
            {
                id: "",
                name: "vm开发",
                desc: "velocity开发，资源文件引用",
                url: ""
            },
            {
                id: "",
                name: "接口开发",
                desc: "功能逻辑流，groovy引用",
                url: ""
            },
            {
                id: "",
                name: "函数库-前端",
                desc: "桌面函数，手机函数库",
                url: ""
            },
            {
                id: "",
                name: "函数库-服务端",
                desc: "模板函数，接口函数，后端函数",
                url: ""
            },
        ]
    },
    // 报表设计
    {
        id: "hceap-bbsj",
        name: "报表设计",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-2.png",
        duration: "",
        watch: "4458",
        children: [

        ]
    },
    // 看板设计
    {
        id: "",
        name: "看板设计",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-1.png",
        duration: "",
        watch: "4223",
        children: [

        ]
    },
    // 功能与流程设计
    {
        id: "hceap-funcflow",
        name: "功能与流程设计",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-2.png",
        duration: "",
        watch: "4022",
        children: [
            {
                id: "",
                name: "功能业务设计",
                desc: "功能业务设计",
                url: ""
            },
            {
                id: "",
                name: "功能权限",
                desc: "模型权限，匿名，环节数据权限",
                url: ""
            },
            {
                id: "",
                name: "流程业务设计入门",
                desc: "流程环节，决策环节，数据权限",
                url: ""
            },
            {
                id: "",
                name: "流程处理",
                desc: "批处理，允许撤回，允许终止",
                url: ""
            },
            {
                id: "",
                name: "流程活动设置",
                desc: "办理人，办理方式，超时处理，额外办理人",
                url: ""
            },
            {
                id: "",
                name: "流程回退设置",
                desc: "允许回退，回退模式，任务返回方式",
                url: ""
            },
            {
                id: "",
                name: "流程转办设置",
                desc: "允许转办，转办人",
                url: ""
            },
            {
                id: "",
                name: "流程加签设置",
                desc: "加签条件，加签办理人",
                url: ""
            },
        ]
    },
    // 高级教程
    {
        id: "hceap-gjjc",
        name: "高级教程",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-1.png",
        duration: "",
        watch: "4123",
        children: [
            {
                id: "",
                name: "请求拦截器",
                desc: "路由配置",
                url: ""
            },
            {
                id: "",
                name: "模板库",
                desc: "视图模板套用",
                url: ""
            },
            {
                id: "",
                name: "调度",
                desc: "调度策略，调度逻辑",
                url: ""
            },
        ]
    },
    // 布署与升级
    {
        id: "hceap-bsysj",
        name: "布署与升级",
        title: "平台精讲",
        desc: "",
        url: "",
        imgUrl: "/images/eapschool/videoTutorial/block1-2.png",
        duration: "",
        watch: "4368",
        children: [
            {
                id: "",
                name: "桌面端环境变量",
                desc: "桌面端环境变量",
                url: ""
            },
            {
                id: "",
                name: "手机端环境变量",
                desc: "手机端环境变量",
                url: ""
            },
            {
                id: "",
                name: "服务端环境变量",
                desc: "服务端环境变量",
                url: ""
            },
            {
                id: "",
                name: "前端组件安装升级",
                desc: "HIUI，MBUI，HI-Taro，主界面，系统功能",
                url: ""
            },
            {
                id: "",
                name: "初始布署",
                desc: "初始布署",
                url: ""
            },
            {
                id: "",
                name: "桌面端编绎",
                desc: "编绎，按需",
                url: ""
            },
            {
                id: "",
                name: "手机端编绎",
                desc: "编绎，按需",
                url: ""
            },
            {
                id: "",
                name: "升级登记",
                desc: "发布登记",
                url: ""
            },
            {
                id: "",
                name: "在线升级与离线升级",
                desc: "升级布署",
                url: ""
            },
        ]
    },
]


function videoInit(_data) {
    $.each(_data, function (index, item) {
        let _li = $("<li class='col-md-6'></li>");
        let _itembox = $("<div class='hc_block1_item'></div>");
        if (item) {
            let _wathc = item.watch || Math.floor(Math.random() * 10000)
            let _seenow = "javascript:;"
            if (item.children.length > 0) {
                _seenow = "/page/eapschool/videoPlay.html?videoid=" + item.id
            }
            let _topitem = ` 
            <div class="hc_block1_item_top">
                <div class="hc_block1_item_img">
                    <img class="hc_block1_cover" src="${item.imgUrl}"
                        alt="">
                    <div class="hc_block1_titlebg">
                        <img class="hc_block1_img2"
                            src="/images/eapschool/videoTutorial/block1-title-bg.png" alt="">
                        <p class="hc_block1_titlebg_text">
                            ${item.title}
                        </p>
                    </div>
                </div>
                <div class="hc_block1_docs">
                    <h4 class="hc_block1_item_title">${item.name}</h4>
                    <div class="hc_block1_item_tiem">
                        <img src="/images/eapschool/videoTutorial/block1-icon.png" alt="">
                        <span>${item.duration}</span>
                    </div>
                    <div class="hc_block1_item_see">
                        <div class="hc_block1_item_num">
                            ${_wathc}人已观看
                        </div>
                        <a href="${_seenow}" class="hc_block1_item_btn">
                            立即观看
                        </a>
                    </div>
                </div>
            </div>`
            _itembox.append(_topitem)
            if (item.children && item.children.length > 0) {
                let children = item.children.slice(0, 2)
                let _bottomitem = $("<div class='hc_block1_item_bottom'></div>");
                let _tags = $("<ul class='hc_block_item_tags'></ul>");
                let _more = `
                <a href="${"/page/eapschool/videoPlay.html?videoid=" + item.id}" class="hc_block_item_tag hc_more">
                    <i class="iconfont icon-jiantou_yemian_xiangyou"></i>
                </a> `
                $.each(children, function (index2, child) {
                    let _p = index2 + 1
                    let cururl = "/page/eapschool/videoPlay.html?videoid=" + item.id + "&p=" + _p
                    let numText = numberTotext(index2 + 1)
                    let _tag = `
                    <a href="${cururl}" class="hc_block_item_tag">
                        第${numText}讲：${child.name}
                    </a>
                   `
                    _tags.append(_tag)
                })
                _bottomitem.append(_tags)
                _bottomitem.append(_more)
                _itembox.append(_bottomitem)
            } else {
                let _bottomitem = `
                <div class="hc_block1_item_bottom">
                    <ul class="hc_block_item_tags">
                        <li class="hc_block_item_tag" style="opacity: 0;">
                            暂无数据
                        </li>
                    </ul>
                    <div class="hc_block_item_tag hc_more" style="opacity: 0;">
                        <i class="iconfont icon-jiantou_yemian_xiangyou"></i>
                    </div> 
                </div>
                `
                _itembox.append(_bottomitem)
            }
        }
        _li.append(_itembox)
        $(".hc_block1_main>ul").append(_li);
    })
}

function numberTotext(number, type = "lower") {
    // 配置
    const confs = {
        lower: {
            num: ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"],
            unit: ["", "十", "百", "千", "万"],
            level: ["", "万", "亿"]
        },
        upper: {
            num: ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"],
            unit: ["", "拾", "佰", "仟"],
            level: ["", "万", "亿"]
        },
        decimal: {
            unit: ["分", "角"]
        },
        maxNumber: 999999999999.99
    };

    // 过滤不合法参数
    if (Number(number) > confs.maxNumber) {
        console.error(
            `The maxNumber is ${confs.maxNumber}. ${number} is bigger than it!`
        );
        return false;
    }

    const conf = confs[type];
    const numbers = String(Number(number).toFixed(2)).split(".");
    const integer = numbers[0].split("");
    const decimal = Number(numbers[1]) === 0 ? [] : numbers[1].split("");

    // 四位分级
    const levels = integer.reverse().reduce((pre, item, idx) => {
        let level = pre[0] && pre[0].length < 4 ? pre[0] : [];
        let value =
            item === "0" ? conf.num[item] : conf.num[item] + conf.unit[idx % 4];
        level.unshift(value);

        if (level.length === 1) {
            pre.unshift(level);
        } else {
            pre[0] = level;
        }

        return pre;
    }, []);

    // 整数部分
    const _integer = levels.reduce((pre, item, idx) => {
        let _level = conf.level[levels.length - idx - 1];
        let _item = item.join("").replace(/(零)\1+/g, "$1"); // 连续多个零字的部分设置为单个零字

        // 如果这一级只有一个零字，则去掉这级
        if (_item === "零") {
            _item = "";
            _level = "";

            // 否则如果末尾为零字，则去掉这个零字
        } else if (_item[_item.length - 1] === "零") {
            _item = _item.slice(0, _item.length - 1);
        }

        return pre + _item + _level;
    }, "");

    // 小数部分
    let _decimal = decimal
        .map((item, idx) => {
            const unit = confs.decimal.unit;
            const _unit = item !== "0" ? unit[unit.length - idx - 1] : "";

            return `${conf.num[item]}${_unit}`;
        })
        .join("");

    // 如果是整数，则补个整字
    // return `${_integer}元` + (_decimal || "整");
    return _integer
};


function getQueryVariable(letiable) {
    let query = window.location.search.substring(1);
    let lets = query.split("&");
    for (let i = 0; i < lets.length; i++) {
        let pair = lets[i].split("=");
        if (pair[0] == letiable) { return pair[1]; }
    }
    return (false);
}